<?php
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'DAO' . DIRECTORY_SEPARATOR . 'AppDAO.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'DAO' . DIRECTORY_SEPARATOR . 'AppLinkDAO.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'DAO' . DIRECTORY_SEPARATOR . 'AppMessageDAO.php';
class AppLinkService {

    public function getAllAppLink($context, $result, $start, $limit) {
        $appLinkArr = null;
        try {
            $appLinkDAO = new AppLinkDAO($context);

            $appLinkArr = $appLinkDAO -> getAllAppLink($start, $limit);
            if (isset($appArr) && !empty($appArr)) {
                $result -> setSuccess();
            } else {
                $result -> setFailed("ERR01", "No App Found");
                $context -> logError("ERR01", "No App Found Call By " . __METHOD__ . " ON " . __CLASS__);
            }
        } catch (Exception $e) {
            $result -> setException($e);
            $context -> logException($e);
        }

        return $appLinkArr;
    }
    
	public function getAppLinkByAppId($context, $result, $id) {
        $appLinkArr = null;
        try {
            $appLinkDAO = new AppLinkDAO($context);

            $appLinkArr = $appLinkDAO -> getAppLinkByAppId($id);
            
        } catch (Exception $e) {
            $result -> setException($e);
            $context -> logException($e);
        }

        return $appLinkArr;
    }

    public function countAppLink($context, $result) {
        $total = 0;
        try {
			$appLinkDAO = new AppLinkDAO($context);

            $total = $appLinkDAO -> countAppLink();
            
        } catch (Exception $e) {
            $result -> setException($e);
            $context -> logException($e);
        }

        return $total;
    }

	public function getAppNameByStatus($context, $result, $status) {
        $appArr = null;
        try {
            $appDAO = new AppDAO($context);

            $appArr = $appDAO -> getAppNameByStatus($status);
            if (isset($appArr) && !empty($appArr)) {
                $result -> setSuccess();
            } else {
                $result -> setFailed("ERR01", "No App Found");
                $context -> logError("ERR01", "No App Found Call By " . __METHOD__ . " ON " . __CLASS__);
            }
        } catch (Exception $e) {
            $result -> setException($e);
            $context -> logException($e);
        }

        return $appArr;
    }
 
	public function getAllAppByName($context, $result, $name) {
        $appArr = null;
        try {
            $appDAO = new AppDAO($context);

            $appArr = $appDAO -> getAllAppByName($name);
            if (isset($appArr) && !empty($appArr)) {
                $result -> setSuccess();
            } else {
                $result -> setFailed("ERR01", "No App Found By Id : " . $id);
                $context -> logError("ERR01", "No App Found By Id : " . $id . " Call By " . __METHOD__ . " ON " . __CLASS__);
            }
        } catch (Exception $e) {
            $result -> setException($e);
            $context -> logException($e);
        }

        return $appArr;
    } 
    
	public function getAppLinkByID($context, $result, $id) {
        $appLinkArr = null;
        try {
            $gameLinkDAO = new AppLinkDAO($context);

            $appLinkArr = $gameLinkDAO -> getAppLinkByID($id);
            if (isset($appArr) && !empty($appArr)) {
                $result -> setSuccess();
            } else {
                $result -> setFailed("ERR01", "No App Found By Id : " . $id);
                $context -> logError("ERR01", "No App Found By Id : " . $id . " Call By " . __METHOD__ . " ON " . __CLASS__);
            }
        } catch (Exception $e) {
            $result -> setException($e);
            $context -> logException($e);
        }

        return $appLinkArr;
    }
    
	public function insertAppLink($context, $result,$param) {
        $appLinkArr = null;
        try {
            $gameLinkDAO = new AppLinkDAO($context);

            $appLinkArr = $gameLinkDAO -> insertAppLink($param);
        } catch (Exception $e) {
            $result -> setException($e);
            $context -> logException($e);
        }
        return $appLinkArr;
    }
    
	public function updateAppLink($context, $result,$param) {
        $appLinkArr = null;
        try {
            $gameLinkDAO = new AppLinkDAO($context);

            $appLinkArr = $gameLinkDAO -> updateAppLink($param);
        } catch (Exception $e) {
            $result -> setException($e);
            $context -> logException($e);
        }
        return $appLinkArr;
    }
    
	public function deleteAppLink($context, $result, $id) {
        try {

            $gameLinkDAO = new AppLinkDAO($context);

            $gameLinkDAO -> deleteAppLink($id);
        } catch (Exception $e) {
            $result -> setException($e);
            $context -> logException($e);
        }
    }
}
?>